
/* License Notice:
**
** This program is free software: you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation, either version 3 of the License, or
**    (at your option) any later version.
** This program is distributed in the hope that it will be useful,
**   but WITHOUT ANY WARRANTY; without even the implied warranty of
**   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
**   GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
**   along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
 * @file window_manager.hpp
 * @author TooOld2Rock'nRoll
 * @date 2024/12/16
 * @brief A collection of useful simplifications for the native window managing system.
 *
 * @todo Collect other bits of the SDL api that may be centralized here.
 */
#ifndef _WINDOW_MANAGER_HPP_
#define _WINDOW_MANAGER_HPP_

/*---- Includes ----*/
#include <SDL2/SDL_video.h>


/*---- Typedefs ----*/


/*---- Class Declaration ----*/
/**
 * @brief A class to hold some global procedures/values regarding the WindowManager API.
 * @remark Thread safe singleton according to Game Programming Patterns, it could also have been implemented as a static class.
 */
class WindowManager
{
    private:
        SDL_Window *p_sdlWindow = nullptr;

        unsigned u_win_width = 0; //in pixels
        unsigned u_win_height = 0; //in pixels

    protected:
        //hide constructor to make singleton safe
        WindowManager ();


    public:
        static WindowManager& instance ();
        ~WindowManager ();

        //delete copy and move constructors and assign operators to make singleton safe
        WindowManager (WindowManager const&) = delete;            //Copy construct
        WindowManager (WindowManager&&) = delete;                 //Move construct
        WindowManager& operator= (WindowManager const&) = delete; //Copy assign
        WindowManager& operator= (WindowManager &&) = delete;     //Move assign

        void init (const char *window_title, unsigned target_display, SDL_WindowFlags window_flags);

        /** @brief Returns a pointer to the native window manager. */
        SDL_Window* getNativeMgrRef () const { return this->p_sdlWindow; }
        /** @brief Returns the window current drawing width in pixels. */
        unsigned getWindowWidth () const { return this->u_win_width; }
        /** @brief Returns the window current drawing height in pixels. */
        unsigned getWindowHeight () const { return this->u_win_height; }

        /** @brief Call it at the end of the rendering cycle to swap buffers and actually print to the screen! */
        void swapWindow () const { SDL_GL_SwapWindow (this->p_sdlWindow); }
};//END WindowManager

#endif //_WINDOW_MANAGER_HPP_

